package org.example.iocdemo.ioc;
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

import org.example.iocdemo.ioc.component.UserComponent;
import org.example.iocdemo.ioc.config.UserConfig;
import org.example.iocdemo.ioc.config.UserInfo;
import org.example.iocdemo.ioc.controller.UController;
import org.example.iocdemo.ioc.controller.UserController;
import org.example.iocdemo.ioc.repo.UserRepository;
import org.example.iocdemo.ioc.service.UserService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;

//@ComponentScan("org.example.iocdemo.ioc")
@SpringBootApplication
public class iocDemoApplication {
    public iocDemoApplication() {
    }

    public static void main(String[] args) {
        // Spring 上下文
        ApplicationContext context=SpringApplication.run(iocDemoApplication.class, args);
       /* // 从 context 中获取bean
        UserController bean = context.getBean(UserController.class);
        bean.doController();

        // 使用类型来获取bean
        UserService userService = context.getBean(UserService.class);
        userService.doService();
        // 使用名称来获取bean
        UserService userService2 = (UserService)context.getBean("userService");
        userService2.doService();
        // 使用类型和名称来获取bean
        UserService userService3 = context.getBean("userService", UserService.class);
        userService3.doService();

        // 特殊情况:当类名的前两个字母都大写的时候,bean的名称是类名
        UController uController = (UController)context.getBean("UController");
        uController.doController();

        UserRepository userRepository = context.getBean(UserRepository.class);
        userRepository.doRepository();

        UserComponent userComponent = context.getBean(UserComponent.class);
        userComponent.doComponent();

        UserConfig userConfig = context.getBean(UserConfig.class);
        userConfig.dpUserConfig();

        //@Bean演示
        UserInfo userInfo= context.getBean("userInfo",UserInfo.class);
        System.out.println(userInfo);*/

        UserController controller=context.getBean(UserController.class);
        controller.doController();
    }
}